package lab.gene.service.impl;

import java.util.Date;
import java.util.List;

import lab.gene.dao.GeneDAO;
import lab.gene.dao.GenePrepFinalsDAO;
import lab.gene.pojo.Gene;
import lab.gene.pojo.GenePrepFinals;
import lab.gene.service.GenePrepFinalsService;
import lab.user.dao.UserDAO;
import lab.user.pojo.User;

public class GenePrepFinalsServiceImpl implements GenePrepFinalsService {

	@Override
	public GenePrepFinals getGenePrepFinalsByNameAndType(String geneName,
			String type) {
		// TODO Auto-generated method stub
		GenePrepFinalsDAO dao = new GenePrepFinalsDAO();
		
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		GenePrepFinals result = dao.getGenePrepFinalsByNameAndType(g, type);
		return result;
	}

	@Override
	public void addGenePrepFinals(String geneName, String type,
			Date date1, Date date2, Date date3, String pcr1, String pcr2,
			int exsize1, int exsize2, String checked1, String checked2,
			String checked3, String comments, String userName) {
		// TODO Auto-generated method stub
		
		UserDAO udao = new UserDAO();
		GeneDAO gdao = new GeneDAO();
		Gene g = gdao.getGene(geneName);
		User u = udao.getUser(userName);
		GenePrepFinalsDAO dao = new GenePrepFinalsDAO();
		GenePrepFinals gf = new GenePrepFinals();
		gf.setChecked1(checked1);
		gf.setChecked2(checked2);
		gf.setChecked3(checked3);
		gf.setComments(comments);
		gf.setDate1(date1);
		gf.setDate2(date2);
		gf.setDate3(date3);
		gf.setDateModified(new Date());
		gf.setExsize1(exsize1);
		gf.setExsize2(exsize2);
		gf.setGene(g);
		gf.setPcr1(pcr1);
		gf.setPcr2(pcr2);
		gf.setType(type);
		gf.setUser(u);
		dao.addGenePrepFinals(gf);
	}
	
	@Override
	public List<GenePrepFinals> getGenePrepFinalsHistory(String geneName, String type) {
		List<GenePrepFinals> g = null;
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		GenePrepFinalsDAO dao = new GenePrepFinalsDAO();
		g = dao.getGenePrepFinalsHistory(gene, type);
		return g;
	}
}
